package com.mgs.product.tagger.handlers
{
	import com.mgs.fwk.context.ApplicationContext;
	import com.mgs.fwk.handlers.ActionHandler;
	import com.mgs.product.tagger.actions.ApplicationAction;
	import com.mgs.product.tagger.actions.LockElementsAction;
	import com.mgs.product.tagger.ui.dto.ClassifiableUI;
	import com.mgs.product.tagger.ui.dto.NavigationContext;
	
	import mx.collections.ArrayList;
	
	public class LockElementsHandler implements ActionHandler
	{
		public function execute(context:ApplicationContext, action:ApplicationAction):void
		{
			var element:ClassifiableUI;
			for each(element in (context as NavigationContext).lockedElements.toArray())
			{
				element.locked = false;
			}
			(context as NavigationContext).lockedElements = new ArrayList();
			for each(element in (action as LockElementsAction).elements)
			{
				var index:int = (context as NavigationContext).lockedElements.getItemIndex(element);
				if(index < 0)
				{
					(context as NavigationContext).lockedElements.addItem(element);
				}
				element.locked = true;
			}
		}
	}
}